package com.example.lab03.controller;

import com.example.lab03.entity.User;
import com.example.lab03.repository.UserRepository;
import com.example.lab03.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("users")
public class UserController {
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }
    @GetMapping("queryAll")
    public List<User> findAll(){
        return userService.queryAll();
    }
    @PostMapping ("create")
    public User create(@RequestBody User user){
        return userService.create(user);
    }
    @GetMapping("queryById/{id}")
    public User queryById(@PathVariable String id){
        return userService.queryById(id);
    }
    @PutMapping ("update")
    public User update(@RequestBody User user){
        return userService.modify(user);
    }
    @DeleteMapping("removeById/{id}")
    public void remove(@PathVariable String id){
        userService.delete(id);
    }

}
